﻿
component  extends="AbsBean" accessors="true" output="false"
{
	property name="status" type="boolean" hint="Login status" default="false";
	property name="user" type="User" hint="User information";
	property name="permissions" type="Permission[]";
	property name="preferences" type="Preference[]";

	public Login function init(){
	
		// setto il valore false come default
		variables.status = false;
		
		return this;
	}
	
	public boolean function havePermission( required String permission ){
		var result = false;
		var iterator = this.getPermissions().iterator();
		
		while( iterator.hasNext() ){
		
			if( iterator.next().getId() eq arguments.permission ){
			
				result = true;
				break;
			
			} 
		
		}
	
		return result;
	}
	
	public boolean function havePreference( required String preference ){
		var result = false;
		var iterator = this.getPreferences().iterator();
		
		while( iterator.hasNext() ){
		
			if( iterator.next().getId() eq arguments.preference ){
			
				result = true;
				break;
			
			} 
		
		}
	
		return result;
	}

}